home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / text+faqs / amigafaqdeutsch / programmer / domethod.asm < prev    next >
Assembly Source File  |  1996-02-26  |  6KB  |  204 lines

  1. *  classface.asm - Intuition object/class method invocation
  2. *  converts "standard" C calling conventions to appropriate
  3. *  hook conventions.
  4. *
  5. * Code in here "freezes" these facts (and no others):
  6. *    - pointer to an object's class immediately precedes the object pointer
  7. *    - pointer to a class's superclass is (h_SIZEOF+4) into the class
  8.  
  9.     INCLUDE 'exec/types.i'
  10.     INCLUDE 'exec/nodes.i'
  11.  
  12.     INCLUDE 'utility/hooks.i'
  13.  
  14. * varargs interfaces for invoking method functions
  15.     xdef    _DoMethod
  16.     xdef    _DoMethodA
  17.     xdef    _DoSuperMethod
  18.     xdef    _DoSuperMethodA
  19.     xdef    _CoerceMethod
  20.     xdef    _CoerceMethodA
  21.     xdef    _SetSuperAttrs
  22.  
  23. * corresponding method invocations for a pre-packaged parameter
  24. * "message" packet
  25.     xdef    _DM
  26.     xdef    _DSM
  27.     xdef    _CM
  28.  
  29. * DoMethod( o, method_id, param1, param2, ... )
  30. * Invoke upon an object the method function defined by an object's class.
  31. * This function (with its "short form" DM() ) is the only one that
  32. * you should use unless you are implementing a class.
  33. *
  34. _DoMethod:
  35.     move.l    a2,-(a7)        ; rely on a6 being preserved
  36.     move.l    8(sp),a2        ; object
  37.     move.l    a2,d0        ; be safe
  38.     beq.s    cmnullreturn
  39.     lea    12(sp),a1       ; message
  40.     move.l    -4(a2),a0       ; object class ptr precedes object
  41.  
  42.     bra.s    cminvoke(pc)    ; will cleanup a2
  43.     ; ----- don't return here
  44.  
  45. _DoMethodA:
  46.     move.l    a2,-(sp)        ; rely on a6 being preserved
  47.     move.l    8(sp),a2        ; object
  48.     move.l    a2,d0        ; be safe
  49.     beq.s    cmnullreturn
  50.     move.l    12(sp),a1       ; message
  51.     move.l    -4(a2),a0       ; object class ptr precedes object
  52.  
  53.     bra.s    cminvoke(pc)    ; will cleanup a2
  54.     ; ----- don't return here
  55.  
  56. * DoSuperMethod( cl, o, method_id, param1, param2, ... )
  57. * Invoke upon an object the method defined for the superclass
  58. * of the class specified.  In a class implementation, you
  59. * are passed a pointer to the class you are implementing, which
  60. * you pass to this function to send a message to the object
  61. * considered as a member of your superclass.
  62. *
  63. _DoSuperMethod:
  64.     move.l    a2,-(a7)        ; rely on a6 being preserved
  65.     movem.l 8(sp),a0/a2     ; class, object
  66.     move.l    a2,d0        ; be safe (object)
  67.     beq.s    cmnullreturn
  68.     move.l    a0,d0        ; be safe (class)
  69.     beq.s    cmnullreturn
  70.     lea    16(sp),a1       ; message (varargs version)
  71.     move.l    h_SIZEOF+4(a0),a0       ; substitute superclass
  72.  
  73.     bra.s    cminvoke(pc)    ; will cleanup a2
  74.     ; ----- don't return here
  75.  
  76. _DoSuperMethodA:
  77.     move.l    a2,-(sp)        ; rely on a6 being preserved
  78.     movem.l 8(sp),a0/a2     ; class, object
  79.     move.l    a2,d0        ; be safe (object)
  80.     beq.s    cmnullreturn
  81.     move.l    a0,d0        ; be safe (class)
  82.     beq.s    cmnullreturn
  83.     move.l    16(sp),a1       ; message (register version)
  84.     move.l    h_SIZEOF+4(a0),a0       ; substitute superclass
  85.  
  86.     bra.s    cminvoke(pc)    ; will cleanup a2
  87.  
  88. * CoerceMethod( cl, o, method_id, param1, param2, ... );
  89. * Invoke upon the given object a method function for whatever
  90. * specified class.  This is sort of the primitive basis behind
  91. * DoMethod and DoSuperMethod.
  92. *
  93. _CoerceMethod:
  94.     move.l    a2,-(a7)        ; rely on a6 being preserved
  95.     movem.l 8(sp),a0/a2     ; get hook and object
  96.     move.l    a2,d0        ; be safe (object)
  97.     beq.s    cmnullreturn
  98.     move.l    a0,d0        ; be safe (class)
  99.     beq.s    cmnullreturn
  100.     lea    16(sp),a1       ; varargs version
  101.     ; --- registers ready, now call hook
  102.     bra.s    cminvoke(pc)
  103.     ; ----- don't return here
  104.  
  105.  
  106. _CoerceMethodA:
  107.     move.l    a2,-(sp)        ;   rely on a6 being preserved
  108.     movem.l 8(sp),a0/a2     ;   get hook and object
  109.     move.l    a2,d0        ;   be safe (object)
  110.     beq.s    cmnullreturn
  111.     move.l    a0,d0        ;   be safe (class)
  112.     beq.s    cmnullreturn
  113.     move.l    16(sp),a1       ;   register version
  114.     ; --- registers ready, now call hook
  115.     bra.s    cminvoke(pc)
  116.     ; ----- don't return here
  117.  
  118. * CM( a0: cl, a2: o, a1: msg )
  119. * This is CoerceMethod for prepackaged "message" packets
  120. *
  121. _CM:
  122.     move.l    a2,-(a7)        ; rely on a6 being preserved
  123.     movem.l 8(sp),a0/a2     ; get class and object
  124.     move.l    a2,d0
  125.     beq.s    cmnullreturn
  126.     move.l    a0,d0
  127.     beq.s    cmnullreturn
  128.     move.l    16(sp),a1       ; get msg
  129.     ; --- registers ready, now call hook
  130.  
  131.     ; --- performs call to hook in A0 and restores a2
  132. cminvoke:
  133.     pea.l    cmreturn(pc)
  134.     move.l    h_Entry(a0),-(sp)
  135.     rts
  136. cmnullreturn:
  137.     moveq.l #0,d0
  138. cmreturn:
  139.     move.l    (sp)+,a2
  140.     rts
  141.  
  142.  
  143. * DM( o, msg )
  144. * This is DoMethod for prepackaged "message" packets
  145. _DM:
  146.     move.l    a2,-(a7)        ; rely on a6 being preserved
  147.     move.l    8(sp),a2        ; object
  148.     move.l    a2,d0
  149.     beq.s    cmnullreturn
  150.     move.l    12(sp),a1       ; message
  151.     move.l    -4(a2),a0       ; object class precedes object
  152.  
  153.     bra.s    cminvoke(pc)    ; will cleanup a2
  154.     ; ----- don't return here
  155.  
  156.  
  157. * DSM( cl, o, msg )
  158. * This is DoSuperMethod for prepackaged "message" packets
  159. _DSM:
  160.     move.l    a2,-(a7)        ; rely on a6 being preserved
  161.     movem.l 8(sp),a0/a2     ; class, object
  162.     move.l    a2,d0
  163.     beq.s    cmnullreturn
  164.     move.l    a0,d0
  165.     beq.s    cmnullreturn
  166.     move.l    16(sp),a1       ; message
  167.     move.l    h_SIZEOF+4(a0),a0       ; substitute superclass
  168.  
  169.     bra.s    cminvoke(pc)    ; will cleanup a2
  170.     ; ----- don't return here
  171.  
  172.  
  173. * SetSuperAttrs( cl, o, tag1, data1, ..., TAG_END );
  174. * A useful varargs conversion to the proper OM_SET method.
  175. _SetSuperAttrs:
  176.     move.l    a2,-(a7)        ; save
  177.  
  178.     movem.l 8(sp),a0/a2     ; class, object
  179.     move.l    a2,d0        ; be safe (object)
  180.     beq.s    cmnullreturn
  181.     move.l    a0,d0        ; be safe (class)
  182.     beq.s    cmnullreturn
  183.  
  184.     move.l    h_SIZEOF+4(a0),a0       ; substitute superclass
  185.  
  186.     ; ----- build msg packet on the stack
  187.     move.l    #0,-(sp)        ; NULL GadgetInfo
  188.     pea.l    4+16(sp)        ; address of tags on deeper stack
  189.     move.l    #$103,-(sp)     ; MethodID OM_SET
  190.     lea.l    (sp),a1         ; put the address of the whole thing in a1
  191.  
  192.     pea.l    ssaret(pc)
  193.     move.l    h_Entry(a0),-(sp)
  194.     rts
  195.  
  196. ssaret:
  197.     ; ----- return here to clean up stack
  198.     lea.l    12(sp),sp       ; pop off three long parameters
  199.     move.l    (sp)+,a2        ; pop/restore original a2
  200.     rts
  201.  
  202.  
  203.     end
  204.